package org.fluidindia.ria.library.remoting
{

	import mx.messaging.ChannelSet;
	import mx.messaging.channels.AMFChannel;
	
	/**
	 * Loads the server end points from a provided XML in a data model.
	 * 
	 */
	public class ChannelFactory
	{
		/**
		 * Default and the constructor to load end points from an XML.
		 */
		public function ChannelFactory(clazz:Private)
		{
		}
		
		
		/**
		 * Creates a Channelset containing various AMF channels using the end points provided. 
		 */
		public static function createChannelSet(remoting:XML):ChannelSet
		{
			var _channelSet:ChannelSet = new ChannelSet();
			
			var channels:Array = loadChannels(remoting);
			
			for(var count:int = 0; count < channels.length; count++)
			{
				var _amfChannel:AMFChannel = new AMFChannel("unsecure-amf", channels[0].getURL());
				_channelSet.addChannel(_amfChannel);
			}
			
			return _channelSet;
		}
		
		private static function loadChannels(remoting:XML):Array
		{
			var count:int = remoting.channels.length();
			
			// Holds all the channels definitions.
			var channels:Array = new Array(count);
			
			for(var i:int = 0; i < count; i++)
			{
				// Load channels
				var channel:Channel = new Channel(remoting.channels.channel[0].server, remoting.channels.channel[0].port, remoting.channels.channel[0].servlet, remoting.channels.channel[0].isSecure);
				channels[i] = channel;
			}
			
			return channels;
		}
	}
}

class Private
{
}	